<html>
<head>
    <meta charset="utf-8">
    <#assign base=request.contextPath  />
    <#setting  number_format="0.##"/>
    <title>规格管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${base}/backstage/layui/css/layui.css" media="all">
    <script src="${base}/backstage/js/jquery-1.8.3.min.js"></script>
    <script src="${base}/backstage/layui/layui.js"></script>
    <script src="${base}/backstage/js/feng.js"></script>
    <script>
        var base =  "${base}";
    </script>
    <script src="${base}/backstage/js/ipNameUrl.js"></script>
    <style>
        /*给数据表格加高*/
        .layui-table-cell{
            height:50%;
        }
    </style>
</head>
<body>
<br>
<div class="demoTable" style="margin-left: 15px;">
    <form class="layui-form " action="">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">分类名称</label>
                <div class="layui-input-inline">
                    <select name="modules" id="commodityId" lay-verify="required" lay-search="" lay-filter="commodityId">
                        <option value="">直接选择分类名称</option>
                        <#list commodity as commodity>
                            <option value="${commodity.id}">${commodity.name}</option>
                        </#list>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">分类名称</label>
                <div class="layui-input-inline">
                    <select name="modules" id="classificationId" lay-verify="required" lay-filter="classificationId" lay-search="">
                    </select>
                </div>
            </div>



            <button class="layui-btn" onclick="sech()" data-method="offset"
                    type="button">查询
            </button>
        </div>
    </form>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="barDemo">
<#--    <button class="layui-btn" lay-event="edit" >编辑</button>&nbsp;-->
    <button class="layui-btn" lay-event="del" onclick="onDelete('{{d.id}}')"
            style="background: red;color: #FFFFFF">删除
    </button>
</script>
<script type="text/html" id="toolbarDemo">
    <form class="layui-form " action="">
        <div class="layui-form-item" style="margin-left: 15px;">
            <div class="layui-btn-group">
                <button class="layui-btn" id="btn2" data-method="offset" type="button">添加</button>
            </div>
        </div>
    </form>
</script>
<script>
    layui.use(['table', 'form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , $ = layui.jquery
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , table = layui.table;

        var whereData = {}
        whereData.classificationId = $("#classificationId").val();
        whereData.commodityId = $("#commodityId").val();

        layui.form.on('select(commodityId)', function(data) {
            var commodityId =  data.value;
            $.ajax({
                type: "GET",
                url: "${base}/admin/public/selectClassifitcation",
                dataType: "json",
                data:{id:commodityId},
                success: function (data) {
                    if(data.code==200){
                        $("#classificationId").html("")
                        $("#classificationId").append(
                            ' <option value=""  >直接选择分类名称</option>'
                        )
                        for (var i = 0; i < data.data.length; i++) {
                            $("#classificationId").append(
                                ' <option value="' + data.data[i].id+ '"  >' + data.data[i].name + '</option>'
                            )

                        }
                        layui.form.render(); //更新全部
                    }

                }
            });
        });

        table.render({
            skin: 'line' //行边框风格
            , even: true //开启隔行背景
            , elem: '#test'
            ,where:whereData
            , url: '${base}/admin/sizeClassification/selectMyPage'
            , toolbar: '#toolbarDemo'
            ,cols:[[
                {field:'id', title: '序号',templet:function(val){
                        return val.LAY_INDEX
                    },align:'center'},
                {field:'commodityName', title: '商品分类', align:'center'},
                {field:'classificationName', title: '分类名称', align:'center'},
                {field:'size', title: '规格大小', align:'center'},
                {field:'createTime', title: '创建时间',templet:function(val){
                        if(val.createTime==undefined){
                            return "";
                        }
                        return changeDateFormat(val.createTime);
                    },  align:'center'},
                {field: 'right', title: '操作', toolbar: '#barDemo', align: 'center'}
            ]]
            , id: 'testReload'
            , page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                , theme: '#1AB394'
                , limit: 10
            }
        });

        //添加
        var active = {
            offset: function (othis) {
                var type = othis.data('type')
                    , text = othis.text();
                window.location.href = '${base}/admin/sizeClassification/sizeClassification_add.html';
            }
        };
        $('#btn2').on('click', function () {
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });

        //编辑弹出层
        table.on('tool(test)', function (obj) {
            var layEvent = obj.event;
            if (layEvent == "edit") {
                var data = obj.data;
                window.location.href = '${base}/admin/money/money_edit.html?id=' + data.id;
            }
        });

    })
    //删除
    function onDelete(id) {
        layer.confirm('真的要删除吗?', function (index) {
            $.ajax({
                type: "POST",
                url: "${base}/admin/sizeClassification/deleteById",
                data: {id: id},
                sync: false,
                success: function (data) {
                    if (data.code === 200) {
                        layer.msg(data.msg)
                        setTimeout(function () {
                            window.location.reload();
                        }, 500)
                    } else {
                        layer.msg(data.msg)
                    }

                }
            });
        });
    }
    //搜索
    function sech() {
        var whereData = {}
        whereData.classificationId = $("#classificationId").val();
        whereData.commodityId = $("#commodityId").val();
        //表刷新方法
        var table = layui.table;
        table.reload('testReload', {
            url: '${base}/admin/sizeClassification/selectMyPage'
            , where: whereData
        });
    }
</script>

</body>

</html>


